493B - Vasya and Wrestling - CodeForces Solution


implementation *1400

Please click on ads to support us..

C++ Code:

#include <iostream>
#include <vector>

using namespace std;

enum Player { ONE, TWO };

Player getWinner() {
  int nMoves;
  cin >> nMoves;
  uint64_t score1 = 0, score2 = 0;
  vector<int64_t> points1;
  vector<int64_t> points2;
  Player lastMoved = Player::ONE;
  for (int i = 0; i < nMoves; i++) {
    int64_t points;
    cin >> points;

    if (points > 0) {
      points1.push_back(points);
      score1 += points;
      lastMoved = Player::ONE;
    } else {
      points2.push_back(-points);
      score2 += -points;
      lastMoved = Player::TWO;
    }
    if (score1 > score2) {
      score1 -= score2;
      score2 -= score2;
    } else {
      score2 -= score1;
      score1 -= score1;
    }
  }

  if (score1 > score2) {
    return Player::ONE;
  }
  if (score1 < score2) {
    return Player::TWO;
  }

  size_t i = 0;
  while (i < points1.size() && i < points2.size()) {
    if (points1[i] > points2[i]) {
      return Player::ONE;
    }
    if (points1[i] < points2[i]) {
      return Player::TWO;
    }
    i++;
  }

  if (points1.size() > points2.size()) {
    return Player::ONE;
  }
  if (points1.size() < points2.size()) {
    return Player::TWO;
  }
  return lastMoved;
}

int main() {
  if (getWinner() == Player::ONE) {
    cout << "first";
  } else {
    cout << "second";
  }
  return 0;
}


Comments

Submit
0 Comments
More Questions

746C - Tram
1278B - A and B
1353D - Constructing the Array
1269C - Long Beautiful Integer
1076A - Minimizing the String
913C - Party Lemonade
1313A - Fast Food Restaurant
681A - A Good Contest
1585F - Non-equal Neighbours
747A - Display Size
285A - Slightly Decreasing Permutations
515C - Drazil and Factorial
1151E - Number of Components
1151F - Sonya and Informatics
556A - Case of the Zeros and Ones
867A - Between the Offices
1569A - Balanced Substring
260A - Adding Digits
1698C - 3SUM Closure
1029B - Creating the Contest
1421A - XORwice
1029A - Many Equal Substrings
1675D - Vertical Paths
1271C - Shawarma Tent
805A - Fake NP
1163A - Eating Soup
787A - The Monster
807A - Is it rated
1096A - Find Divisible
1430C - Numbers on Whiteboard